<?php
/**
 * Setup application
 *
 * @author Lukas Normantas
 */
class Areal_Controller_Plugin_Init extends Zend_Controller_Plugin_Abstract
{
    function preDispatch(Zend_Controller_Request_Abstract $request) {
            $module = $request->getModuleName();
            $controller = $request->getControllerName();
            $action = $request->getActionName();
            $language = $request->getParam('language');
            $view = Zend_Layout::getMvcInstance()->getView();
            $view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
            if (in_array($action, array('admin','edit','add','delete'))){
                Zend_Layout::getMvcInstance()->setLayout('admin');
            }
            $view->module = $module;
            $view->controller = $controller;
            $view->action = $action;
            $view->language = $language;
            $front = Zend_Controller_Front::getInstance();
            $front->getRouter()->setGlobalParam('language', $request->getParam('language') );
            if ($this->getRequest()->isXmlHttpRequest()) {
                $view->disableLayout();
            }
    }
}